* carbon_price pasted from Excel carbon_price_wb (WB)
rename var1 year

* reshape to the long data
reshape long price_, i(year) j(country) string

save "C:\Users\USERNAME\Documents\carbon_price.dta"

* pcgdp pasted from Excel
rename var1 year
reshape long pcgdp_, i(year) j(country) string

sort country year

merge 1:1 year country using "C:\Users\USERNAME\Documents\carbon_price.dta"

* country names should be converted to country_id
encode country, generate(country_id)

* panel data recognized
xtset country_id year

replace pcgdp=pcgdp_/1000

* pooled OLS
qui reg price_ pcgdp
est sto reg1

qui reg price_ pcgdp year
est sto reg2

* panel data regression
qui xtreg price_ pcgdp, fe
est sto reg3

qui xtreg price_ pcgdp year, fe
est sto reg4

*random effects could be checked by 
*xtreg price_ pcgdp year, re

* output to tex
ssc install estout, replace

esttab * using "C:\Users\USERNAME\Documents\stataresult.tex.txt", se r2 star(* 0.1 ** 0.05 *** 0.01) b(3) replace
